package com.yiren.dbaa.module.practice_set.site.model;

import android.app.Activity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yiren.dbaa.constant.AddressConstant;
import com.yiren.dbaa.currency.api.CommonCallBack;
import com.yiren.dbaa.module.practice_set.site.contract.OpenSiteRuleContract;
import com.yiren.dbaa.net.OkHttpUtils;
import com.yiren.dbaa.net.bean.TestBaseBean;
import com.yiren.dbaa.net.interf.StringCallback;

/**
 * @author lwb
 * @date : 2022/10/17 8:49
 * @description: 已公开考规Model
 */
public class OpenSiteRuleModel implements OpenSiteRuleContract.Model {

    private Gson gson;
    private Activity activity;

    public OpenSiteRuleModel(Activity activity) {
        this.activity = activity;
        gson = new Gson();
    }

    @Override
    public void changeSiteRuleState(int state,String userId,double rulver,String siteCode,CommonCallBack callBack) {
        OkHttpUtils.getInstance().getStringByAsync(activity, AddressConstant.updateSiteRuleState("?state=" + state+"&userId="+userId+"&siteCode="+siteCode+"&ruleVer="+rulver),
                new StringCallback() {
            @Override
            public void getString(String result) {
                TestBaseBean<String> testBaseBean = gson.fromJson(result,new TypeToken<TestBaseBean<String>>() {}.getType());
                if (testBaseBean.isSuccess()){
                    callBack.success(testBaseBean.getData());
                }else {
                    callBack.fail("设置失败!");
                }
            }

            @Override
            public void getFail() {
                callBack.fail("数据请求失败!");
            }
        });
    }

}
